﻿namespace SmartSoft.DAL
{
    using System;
    using System.Data;
    using System.Data.SqlClient;using NLog;

    public class PriceCalculateDataAccess
    {
        private static Logger log = LogManager.GetCurrentClassLogger();
        public void Calculate0(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_Ma_Kho, object ps_Ma_Vt)
        {
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Ngay_Ct1", pd_Ngay_Ct1), new SqlParameter("p_Ngay_Ct2", pd_Ngay_Ct2), new SqlParameter("p_Ma_Kho", ps_Ma_Kho), new SqlParameter("p_Ma_Vt", ps_Ma_Vt) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Tinh_Gia_TBDD";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
        }

        public void Calculate1(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_Ma_Kho, object ps_Ma_Vt)
        {
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Ngay_Ct1", pd_Ngay_Ct1), new SqlParameter("p_Ngay_Ct2", pd_Ngay_Ct2), new SqlParameter("p_Ma_Kho", ps_Ma_Kho), new SqlParameter("p_Ma_Vt", ps_Ma_Vt) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Tinh_Gia_TBTH";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
        }
        public void Calculate2(string ps_Subsidiary, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_Ma_Kho, object ps_Ma_Vt)
        {
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Ngay_Ct1", pd_Ngay_Ct1), new SqlParameter("p_Ngay_Ct2", pd_Ngay_Ct2), new SqlParameter("p_Ma_Kho", ps_Ma_Kho), new SqlParameter("p_Ma_Vt", ps_Ma_Vt) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Tinh_Gia_NTXT";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
        }

    }
}

